using System;

namespace RapidHDL
{
	/// <summary>
	/// Summary description for NotGate.
	/// </summary>
	public class NotGate : Component
	{
		public NodeVector InputNodes;
		public NodeVector OutputNodes;

		private Not[] oNots;

		int iInputWidth;

		public NotGate(Component poParentComponent, string psName, int piInputWidth) : base (poParentComponent,psName)
		{
			iInputWidth = piInputWidth;
			InputNodes = this.CreateNodeVector("In",iInputWidth);
			OutputNodes = this.CreateNodeVector("Out",iInputWidth);
			oNots = new Not[iInputWidth];
			for (int iIndex = 0; iIndex < iInputWidth; iIndex++)
			{
				oNots[iIndex] = new Not(this,"not" + iIndex.ToString());
				oNots[iIndex].InputNodes[0] = InputNodes[iIndex];
				oNots[iIndex].OutputNodes[0] = OutputNodes[iIndex];
			}
		}

		protected override Component TestBuildStructure(Component poTopComponent, string psTestName)
		{
			return new NotGate(poTopComponent,"testNotGate",3);
		}

		protected override string TestComponent(Clock poClock, Component poTestComponent, string psTestName)
		{
			string sTestId;
			NotGate oNotGate = (NotGate)poTestComponent;

			sTestId = "001 = 110";
			oNotGate.InputNodes.NodeVectorAsString = "001";
			poClock.DoClock(1.0);
			if(oNotGate.OutputNodes.NodeVectorAsString != "110")
				return sTestId;

			sTestId = "000 = 111";
			oNotGate.InputNodes.NodeVectorAsString = "111";
			poClock.DoClock(1.0);
			if(oNotGate.OutputNodes.NodeVectorAsString != "000")
				return sTestId;

			sTestId = "x01 = x10";
			oNotGate.InputNodes.NodeVectorAsString = "x01";
			poClock.DoClock(1.0);
			if(oNotGate.OutputNodes.NodeVectorAsString != "x10")
				return sTestId;

			return "";
		}
	}
}
